<?php

/*
 * Action
 * 
 * 4$
 * 
 * You may trash a Treasure from your hand. If you do, choose one:
 * +2 Cards and +1 Action;
 * or +$2 and +1 Buy.
 * 
 */

class SpiceMerchant extends Card implements iAction, iKingdom, iHinterlands {

    public function __construct() {
        parent::__construct("Spice Merchant", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "You may trash a Treasure from your hand. If you do, choose one: +2 Cards and +1 Action;or +$2 and +1 Buy.");
    }

    public function play(Game $game, $isRealCard) {
        $playHand = $game->getPlayHand();
        $treasures = array();
        foreach ($playHand as $card) {
            if ($card instanceof iTreasure) {
                $treasures[] = $card;
            }
        }
        
        if (sizeof($treasures) > 0) {
            $treasures = getUniqueCards($treasures);
            $treasures[] = new Option(1, 'None');

            $output = MySocket::GetUserReply($game, Input_ChooseOne, $treasures, 1, 1, null, "Choose card to trash");
            $answer = $output[0];
            if ($answer != 'None') {
                $card = $game->moveCardFromPileToPile($answer, PlayHand, Trash);
                ScreenDisplay::addScreenMessage($game, true, "trash ".  nicePrint($card), " trashes ".ScreenDisplay::$LMSG);
                
                $options = array();
                $options[] = new Option(1, "2 cards and 1 action");
                $options[] = new Option(2, "1 buy and 2$");
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Please choose ");
                $answer = $output[0];
                if ($answer =="2 cards and 1 action") {
                    $game->addActions(1);
                    $drawed_cards = $game->drawCards(2);
                    ScreenDisplay::addScreenMessage($game, false, ", get +1 action and draw " . nicePrint($drawed_cards), ", gets +1 action and draws " . sizeof($drawed_cards) . " cards");
                }
                else {
                    $game->addBuys(1);
                    $game->addMoney(new Price(2));
                    ScreenDisplay::addScreenMessage($game, false, ", get +1 buy and 2$", ", gets +1 buy and 2$");
                }
            } else {
                ScreenDisplay::addScreenMessage($game, true, "trash nothing  ", " trashes nothing");
            }
        } else {
            ScreenDisplay::addScreenMessage($game, true, "trash nothing  ", " trashes nothing");
        }
    }

}